<input type="text" id="<?php echo $this->fieldId; ?>" class="input inp_mediatags" name="<?=$this->fieldName;?>" value="<?=htmlspecialchars($this->data);?>">
<script type="text/javascript">
$(document).ready(function() {
		function split( val ) {
			return val.split( /,\s*/ );
		}
		
		function extractLast( term ) {
			return split( term ).pop();
		}

		$( "#<?php echo $this->fieldId; ?>" ).autocomplete({
			source: function( request, response ) {
				$.getJSON( "<?=Mozg::Router('http')->Create('module=admin&ctrl=tags&action=list');?>", {
					tag: extractLast( request.term ),
					area: "<?php echo isset($this->params['area']) ? $this->params['area'] : ''; ?>"
				}, response );
			},
			minLength: 2,
			focus: function() {
				// prevent value inserted on focus
				return false;
			},
			select: function( event, ui ) {
				var terms = split( this.value );
				// remove the current input
				terms.pop();
				// add the selected item
				terms.push( ui.item.value );
				// add placeholder to get the comma-and-space at the end
				terms.push( "" );
				this.value = terms.join( ", " );
				return false;
			}
		});

		
});
</script>